A guide to setting up the Default Web Root and Document Root for WordPress.
Before creating files, it is crucial to understand the distinction between the Default Web Root and the Document Root.
/var/www/. This is the top-level directory
created when Nginx is installed./var/www/yourdomain.com/public_html. This is
where your specific site files reside.Why use public_html?
Isolating your site files inside a public_html subdirectory enhances security. Only files
within this folder are accessible via the web server, preventing direct access to system or configuration
files located one level up.
To visualize our directory structure easily, we will install a utility called tree. First, we
must update our package list.
Once the system is updated, install the utility:
We will now create the directories for your domain. We need to navigate to the default web root and create a
folder for the domain, followed by the public_html subfolder.
Navigate to the web root and create directories individually:
You can create a parent directory and its subdirectory simultaneously using the -p flag. This is
faster and cleaner.
You can verify the structure using the tree command:
During setup, you may need to rename or delete directories. Here is how to handle these operations safely.
If you made a typo (e.g., example.grow instead of example.org), use the move
command. Warning: Do not rename directories after configuring Nginx server blocks, as this
will break your site.
If a directory is empty, use rmdir. If it contains files (like the public_html folder), you must
use rm with the recursive force flags.
To remove an empty directory:
To remove a directory and all its contents:
rm -rf command is powerful. There is no "undelete" or recycle bin
in the command line. Verify your spelling before pressing enter.
For our live example, we are setting up the site expertwp.help. We will create the full path in one command.
Your directories are now ready. The next stage in the process will involve configuring Nginx Server Blocks (Virtual Hosts) to serve content from this new location.